﻿@model PaymentMethodRestrictionModel

@{
    //page title
    ViewBag.Title = T("Admin.Configuration.Payment.MethodRestrictions").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Payment method restrictions");
}


<form asp-controller="Payment" asp-action="MethodRestrictions" method="post">
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Admin.Configuration.Payment.MethodRestrictions")
        </h1>
        <div class="pull-right">
            <button type="submit" name="save" class="btn bg-blue">
                <i class="fa fa-floppy-o"></i>
                @T("Admin.Common.Save")
            </button>
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = "admin_payment_method_restrictions_list_buttons" })
        </div>
    </div>

    <div class="content">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <p>@T("Admin.Configuration.Payment.MethodRestrictions.Description")</p>
                        @if (Model.AvailablePaymentMethods.Count == 0)
                        {
                        <text>No payment methods installed</text>
                        }
                        else if (Model.AvailableCountries.Count == 0)
                        {
                        <text>No countries available</text>
                        }
                        else
                        {
                        <script type="text/javascript">
                                $(document).ready(function () {
                                    @foreach (var pm in Model.AvailablePaymentMethods)
                                    {
                                        var systemNameWithoutDot = pm.SystemName.Replace(".", "");
                                        <text>
                                            $('#selectall-@(systemNameWithoutDot)').click(function () {
                                                $('.restrict_@(systemNameWithoutDot)').attr('checked', $(this).is(':checked')).change();
                                            });
                                        </text>
                                    }
                                });
                        </script>
                        <table class="table table-hover table-bordered">
                            <tbody>
                                <tr>
                                    <th scope="col" style="padding-top: 14px;">
                                        <strong>@T("Admin.Configuration.Payment.MethodRestrictions.Country")</strong>
                                    </th>
                                    @foreach (var pm in Model.AvailablePaymentMethods)
                                                {
                                                    var systemNameWithoutDot = pm.SystemName.Replace(".", "");
                                                <th scope="col">
                                                    <div class="checkbox">
                                                        <label>
                                                            <input type="checkbox" id="selectall-@(systemNameWithoutDot)" />
                                                            <strong>@pm.FriendlyName</strong>
                                                        </label>
                                                    </div>
                                                </th>
                                                }
                                </tr>
                                @foreach (var c in Model.AvailableCountries)
                                            {
                                            <tr>
                                                <td>
                                                    <span>@c.Name</span>
                                                </td>
                                                @foreach (var pm in Model.AvailablePaymentMethods)
                                                    {
                                                        var restricted = Model.Resticted.ContainsKey(pm.SystemName) && Model.Resticted[pm.SystemName][c.Id];
                                                        var systemNameWithoutDot = pm.SystemName.Replace(".", "");
                                                    <td>
                                                        <input class="restrict_@(systemNameWithoutDot)" type="checkbox" value="@(c.Id)" name="restrict_@(pm.SystemName)" @(restricted ? " checked=checked" : null) />
                                                    </td>
                                                    }
                                            </tr>
                                            }
                            </tbody>
                        </table>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>